﻿
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IotContract.Models.Clients.Hks;
/// <summary>
/// 杭可写入数据
/// </summary>
[ProtoContract]
public class HkWriteInstruct : ICloneable
{
    
    [ProtoMember(1)]
    public string Num { get; set; }

    /// <summary>
    /// 控制命令
    /// </summary>
    [ProtoMember(2)]
    public string Command { get; set; }
    /// <summary>
    /// 数据
    /// </summary>
    [ProtoMember(3)]
    public string Data { get; set; }


    /// <summary>
    /// 库位
    /// </summary>
    [ProtoMember(4)]
    public int Stage { get; set; }


    /// <summary>
    /// 托盘号
    /// </summary>
    [ProtoMember(5)]
    public string TrayID { get; set; }

    /// <summary>
    /// 库位2
    /// </summary>
    [ProtoMember(6)]
    public int Stage2 { get; set; }

    [ProtoMember(7)]
    public string TrayID2 { get; set; }

    /// <summary>
    /// 堆垛机编码2
    /// </summary>
    [ProtoMember(8)]
    public string Num2 { get; set; }

    /// <summary>
    /// 预约时间
    /// </summary>
    [ProtoMember(9)]
    public DateTime? AppointTime { get; set; }

    /// <summary>
    /// 拥有堆垛机任务 1   已经开始充电 2
    /// </summary>
    [ProtoMember(10)]
    public int Status { get; set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    [ProtoMember(11)]
    public DateTime? CreateTime { get; set; }
    /// <summary>
    /// 错误信息
    /// </summary>
    [ProtoMember(12)]
    public string ErrorMsg { get; set; }

    /// <summary>
    /// 超时或者完成
    /// </summary>
    /// <returns></returns>
    public bool IsAppointOrTimeout()
    {
        if (AppointTime != null && DateTime.Now.Subtract(AppointTime.Value).TotalMinutes > 4)
        {
            return true;
        }
        if (DateTime.Now.Subtract(CreateTime.Value).TotalMinutes > 5)
        {
            return true;
        }
        return false;
    }


    public object Clone()
    {
        return MemberwiseClone();
    }

    public override string ToString()
    {
        return $"HkNum:{Num},Command:{Command},Stage:{Stage},TrayID:{TrayID}";
    }
}
